<template>
	<view class="box">
		<u-navbar title="更多" :fixed="true" :placeholder="true" :safeAreaInsetTop="true" :autoBack="false"
				leftIconColor="#666" titleStyle="color:#333" bgColor="#E0DDDA" 
				@leftClick="leftClick"></u-navbar>

		<view class="main">
				<view class="item" >
					<image :src="info.head_img" mode="aspectFill"></image>
					<text>{{info.nickname}}</text>
					<view class="tag" v-if="info.is_admin==1">
						群主
					</view>
					<view class="tag"  v-if="info.is_admin==2" >
						管理员
					</view>
				
				</view>
		
		</view>
		<view class="wrap" >
			<text>设置管理员</text>
			<u-switch v-model="isflag" @change="changestatus" activeColor="#A68A64"
				inactiveColor="rgb(230, 230, 230)"></u-switch>
		</view>
		<view class="wrap" v-if="info.is_admin==0" >
			<text>禁言该成员</text>
			<u-switch v-model="isflag2" @change="changestatus2" activeColor="#A68A64"
				inactiveColor="rgb(230, 230, 230)"></u-switch>
		</view>
		<view style="width: 750rpx;height: 88rpx;">
			
		</view>
	</view>
</template>

<script>
	import {groupMemberDetails,groupDetails,setAdministrator,blockUserSendMsgToGroup,unblockUserSendMsgToGroup} from "../../api/hx.js"
	export default{
		data(){
			return{
				info:{},
				isflag:false,
				isflag2:false,
				groupid:"",
				is_admin:""
			}
		},
		onLoad(option) {
			this.info=uni.getStorageSync("groupitem")
			if(this.info.is_admin==2){
				this.isflag=true
			}
			if(this.info.is_admin==0){
				this.isflag=false
			}
			if(this.info.is_forbidden_speech==1){
				this.isflag2=true
			}
			if(this.info.is_forbidden_speech==0){
				this.isflag2=false
			}
			this.groupid=option.id
			console.log(this.info)
		},
		onShow() {
			
		},
		methods:{
			set(){
				console.log(this.is_admin)
				setAdministrator({
					hx_group_id:this.groupid,
					is_admin:this.is_admin,
					admin_member_id	:this.info.member_id
				}).then(res=>{
					uni.$u.toast(res.msg)
				})
			},
			unmute(){
				unblockUserSendMsgToGroup({
					hx_group_id:this.groupid,
					user_ids:this.info.member_id
				}).then(res=>{
					uni.$u.toast(res.msg)
					
				})
			},
			mute(){
				blockUserSendMsgToGroup({
					hx_group_id:this.groupid,
					user_ids:this.info.member_id
				}).then(res=>{
					uni.$u.toast(res.msg)
				})
			},
			changestatus2(e){
				if(e==true){
					this.mute()
				}
				if(e==false){
					this.unmute()
				}
			},
			changestatus(e){
				console.log(e)
				if(e==true){
					this.is_admin="2"
					this.set()
				}
				if(e==false){
					this.is_admin="0"
					this.set()
				}
				console.log(this.is_admin)
			},
			leftClick() {
				//获取页面栈的长度
				const canNavBack = getCurrentPages()
				console.log(canNavBack.length);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
		}
	}
</script>
<style>
	page{
		background-color:#E0DDDA;
	}
</style>
<style lang="scss">
	.box{
		width: 750rpx;
		
	}
	/deep/ .u-navbar__content__right__text {
		color: #FF1616;
	}
	.wrap_top{
		width: 750rpx;
	}
	.search{
		width: 690rpx;
		height: 72rpx;
		background: #342857;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		margin: 0 auto;
		position: relative;
		>image{
			width: 32rpx;
			height: 30rpx;
			position: absolute;
			top: 22rpx;
			left: 34rpx;
			
		}
		>input{
			width: 620rpx;
			padding-left: 70rpx;
			height: 72rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: rgba(255,255,255,0.8);
		}
	}
	.main{
		width: 750rpx;
		
	}
	.item{
		width: 690rpx;
		margin: 0 auto;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		position: relative;
		>image{
			width: 84rpx;
			height: 84rpx;
			border-radius: 50%;
		}
		>text{
			font-weight: 400;
			font-size: 30rpx;
			color: #333;
			margin-left: 15rpx;
			max-width: 300rpx;
			white-space: nowrap; /* 防止文本换行 */
			  overflow: hidden;   /* 隐藏溢出的文本 */
			  text-overflow: ellipsis; /* 当文本溢出时显示省略号 */
		}
		.tag{
			padding: 5rpx 10rpx 5rpx 10rpx;
			background: #A68A64;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			opacity: 0.5;
			font-size: 20rpx;
			color: #fff;
			text-align: center;
			margin-left: 20rpx;
		}
		
	}
	/deep/.uni-checkbox-input {
		width: 30rpx;
		height: 30rpx;
		position: absolute;
		right: 40rpx;
		border-radius: 50%;
	}
	.wrap {
		width: 690rpx;
		margin: 0 auto;
		margin-top: 40rpx;
		display: flex;
		align-items: center;
		height: 80rpx;
		justify-content: space-between;
	
		>text {
			font-weight: 400;
			font-size: 32rpx;
			color: #333;
		}
	}
</style>